package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ChangePayModelBean;
import com.shop2cn.iapi.agentproducts.parameter.GetProductListBean;
import com.shop2cn.iapi.agentproducts.parameter.ModifyAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.service.AddAgentProductCall;
import com.shop2cn.iapi.agentproducts.service.ChangePayModelCall;
import com.shop2cn.iapi.agentproducts.service.ModifyAgentProductCall;
import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.SetPayModeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.SetPayModeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
 * 切换支付方式商户服务回调Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ChangePayModel {
	private static ChangePayModelBean changepaymodelBean;
	private static ChangePayModelCall changepaymodelCall;
	
	
	private static SetPayModeBean setpaymodeBean;
	private static SetPayModeCall setpaymodeCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("切换支付方式商户服务回调Test");
	}

	@Before
	public void caseUp() {
		changepaymodelBean = new ChangePayModelBean();
		changepaymodelCall = new ChangePayModelCall();
		
		
		setpaymodeBean=new SetPayModeBean();
		setpaymodeCall=new SetPayModeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(changepaymodelCall.getOpurl());

	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangePayModel_0001() {
		Logger.start(true, "切换到盛付通，成功");
		try {
			// 创建一个渠道商，单规格渠道商品， 获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			changepaymodelBean.setUserId(mchId);
			changepaymodelBean.setPayMode(3);
			changepaymodelCall.setData(changepaymodelBean);
			changepaymodelCall.callService();
			Logger.verifyEquals("ok", changepaymodelCall.getReturnData(), "验证回调是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangePayModel_001() {
		Logger.start(true, "切换到盛付通，成功");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangePayModel_002() {
		Logger.start(true, "切换到盛付通，下架商品，成功");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			AddAgentProductCallService.SetOnshelf(pid, mchId);
			Thread.sleep(2000);
			GetProductListBean initGetProductListBean = new GetProductListBean();
			initGetProductListBean.setUserId(mchId);
			initGetProductListBean.setProductIds(Arrays.asList(pid));
			JsonObject productlist = AddAgentProductCallService.GetProductListCallToJsonobject(initGetProductListBean);
			JsonObject data1 = productlist.get("data").getAsJsonObject();
			Logger.verifyEquals(1, data1.get("totalsNum").getAsInt(), "验证总数");
			Logger.verifyEquals(1, data1.get("onsaleNum").getAsInt(), "验证上架");
			Logger.verifyEquals(0, data1.get("offsaleNum").getAsInt(), "验证下架");
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Thread.sleep(2000);
			JsonObject productlist1 = AddAgentProductCallService.GetProductListCallToJsonobject(initGetProductListBean);
			JsonObject data = productlist1.get("data").getAsJsonObject();
			Logger.verifyEquals(1, data.get("totalsNum").getAsInt(), "验证总数");
			Logger.verifyEquals(0, data.get("onsaleNum").getAsInt(), "验证上架");
			Logger.verifyEquals(1, data.get("offsaleNum").getAsInt(), "验证下架");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangePayModel_003() {
		Logger.start(true, "切换盛付通，发布外币商品，发布失败");
		try {

			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			AddAgentProductCall addAgentProductCall = new AddAgentProductCall();
			addAgentProductCall.setData(addAgentProductBean);
			addAgentProductCall.callService();
			Logger.verifyEquals(201, addAgentProductCall.getJsonObject().get("code").getAsInt(), "添加商品失败");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangePayModel_004() {
		Logger.start(true, "切换到盛付通，发布人民币商品，改成美元，修改失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.setCurrency("CNY");
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			AddAgentProductCallService.SetOnshelf(pid, mchId);
			Thread.sleep(2000);
			GetProductListBean initGetProductListBean = new GetProductListBean();
			initGetProductListBean.setUserId(mchId);
			initGetProductListBean.setProductIds(Arrays.asList(pid));
			JsonObject productlist = AddAgentProductCallService.GetProductListCallToJsonobject(initGetProductListBean);
			JsonObject data1 = productlist.get("data").getAsJsonObject();
			Logger.verifyEquals(1, data1.get("totalsNum").getAsInt(), "验证总数");
			Logger.verifyEquals(1, data1.get("onsaleNum").getAsInt(), "验证上架");
			Logger.verifyEquals(0, data1.get("offsaleNum").getAsInt(), "验证下架");
			
			ModifyAgentProductBean initModifyAgentProductBean = AddAgentProductCallService.initModifyAgentProductBean(pid, addAgentProductBean);
			initModifyAgentProductBean.setCurrency("USD");
			ModifyAgentProductCall modifyAgentProductCall = new ModifyAgentProductCall();
	        modifyAgentProductCall.setData(initModifyAgentProductBean);
	        modifyAgentProductCall.callService();
			Logger.verifyEquals(201, modifyAgentProductCall.getJsonObject().get("code").getAsInt(), "修改商品失败");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangePayModel_006() {
		Logger.start(true, "发布人民币商品，切换到盛付通，修改成美元，修改失败");
		try {

			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.setCurrency("CNY");
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			AddAgentProductCallService.SetOnshelf(pid, mchId);
			Thread.sleep(2000);
			GetProductListBean initGetProductListBean = new GetProductListBean();
			initGetProductListBean.setUserId(mchId);
			initGetProductListBean.setProductIds(Arrays.asList(pid));
			JsonObject productlist = AddAgentProductCallService.GetProductListCallToJsonobject(initGetProductListBean);
			JsonObject data1 = productlist.get("data").getAsJsonObject();
			Logger.verifyEquals(1, data1.get("totalsNum").getAsInt(), "验证总数");
			Logger.verifyEquals(1, data1.get("onsaleNum").getAsInt(), "验证上架");
			Logger.verifyEquals(0, data1.get("offsaleNum").getAsInt(), "验证下架");
			
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Thread.sleep(1000);
			ModifyAgentProductBean initModifyAgentProductBean = AddAgentProductCallService.initModifyAgentProductBean(pid, addAgentProductBean);
			initModifyAgentProductBean.setCurrency("USD");
			ModifyAgentProductCall modifyAgentProductCall = new ModifyAgentProductCall();
	        modifyAgentProductCall.setData(initModifyAgentProductBean);
	        modifyAgentProductCall.callService();
			Logger.verifyEquals(201, modifyAgentProductCall.getJsonObject().get("code").getAsInt(), "修改商品失败");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}



}